﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using NotifiableLinqTests.FrameWork;
using NUnit.Framework;
//using Obtics.Collections;
using Obtics.Values;

namespace OtherFrameworksTests
{
	[TestFixture]
	public class Obtics_samples_bug_1_all : ItemNotificationTestsBase
	{
		[Test]
		public void Simple_test()
		{
			var source = new[] { new Item(6) };
			var query = Obtics.Collections.ObservableEnumerable.All(source, x => x.Width > 5);
			// comment this line, and test will pass. This is a bug
			((INotifyPropertyChanged)query).PropertyChanged += delegate { };
			Assert.IsTrue(query.Value);
			source[0].Width = 3;
			Assert.IsFalse(query.Value);
		}

		[SetUp]
		public void SetUp()
		{
			SetupEnvironment();
		}

		[Test]
		public void Run()
		{
			_listener.PerformAssert();
			_source[0].Width = 2;
			_listener.PerformAssert();
		}

		public override IEnumerable<IItem> SourceInitialize()
		{
			yield return new Item(6);
		}

		public override object QuerySut(IEnumerable<IItem> source)
		{
			// try Live Linq - there are no such bug
			// return LiveLinq.ObservableEnumerable.All(source, x => x.Width > 5);
			return Obtics.Collections.ObservableEnumerable.All(source, x => ExpressionObserver.Execute(() => x.Width > 5));
		}

		public override object QueryActual(IEnumerable<IItem> source)
		{
			return System.Linq.Enumerable.All(source, x => x.Width > 5);
		}
	}
}
